﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace loveMotorcade.web.Areas.manage.Controllers
{
    using Models;
    using Classes;
    using Filters;

    public class orderController : Controller
    {
        //
        // GET: /manage/order/

        public ActionResult Index(string orderField="",string keyword="")
        {
            ModelContainer db = new ModelContainer();
            IQueryable<order> vmodel = db.order;
            switch (orderField) { 
                case "disable":
                    vmodel = vmodel.Where(d => d.disable == true);
                    break;
                case "name":
                    vmodel = vmodel.Where(d=>d.user.name.Contains(keyword));
                    break;
                case "linkname":
                    vmodel = vmodel.Where(d => d.linkman.Contains(keyword));
                    break;
                case "type":
                    vmodel = vmodel.Where(d => d.type == keyword);
                    break;
                default:
                    vmodel = db.order;
                    break;
            }
            vmodel = vmodel.OrderByDescending(d => d.editDate);
            ViewData.Model = db.order.OrderByDescending(d=>d.editDate);
            return View();
        }

        public ActionResult Create()
        {

            return View();
        }

        //
        // POST: /manage/order/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }



        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /manage/order/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }


        [HttpPost]
        public ActionResult disable(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
